<!-- INCLUDE overall_header.html -->
<SCRIPT>
function validate() 
{
//	alert('validate');
	
	username = new_openid.username.value;
	if (username == '') 
	{
		alert('{L_PLEASE_INPUT}{L_USERNAME}');
		event.returnValue = false;
		new_openid.username.focus();
		return;
	}
	email = new_openid.email.value;
	if (email == '') 
	{
		alert('{L_PLEASE_INPUT}{L_EMAIL_ADDRESS}');
		event.returnValue = false;
		new_openid.email.focus();
		return;
	}
	if (is_valid_mail(email) == false)
	{
		alert('{L_EMAIL_INVALID_EMAIL}');
		event.returnValue = false;
		new_openid.email.focus();
		return;		
	}
	if (document.forms['new_openid'].username_check.value == 0)
	{
		alert('{L_USERNAME_DISALLOWED_USERNAME}');
		event.returnValue = false;
		new_openid.username.focus();
		return;
	}
	if (document.forms['new_openid'].email_check.value == 0)
	{
		alert('{L_EMAIL_TAKEN_EMAIL}');
		event.returnValue = false;
		new_openid.email.focus();
		return;
	}
	
	// debug
//	if (confirm('validate end, send out ?') == false)
//		event.returnValue = false;
}

function is_valid_mail(email)
{	
	var emailRegEx = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
	if (email.search(emailRegEx) == -1) 
	{
          return false;
	}

	return true;
}

</SCRIPT>
<script language="Javascript">
function xmlhttpPost(strURL, query, func) 
{
    var xmlHttpReq = false;
    var self = this;
    // Mozilla/Safari
    if (window.XMLHttpRequest) 
	{
        self.xmlHttpReq = new XMLHttpRequest();
    }
    // IE
    else if (window.ActiveXObject) 
	{
        self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
    }
    self.xmlHttpReq.open('POST', strURL, true);
    self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    self.xmlHttpReq.onreadystatechange = func;     
    self.xmlHttpReq.send(query);
}

function check_username()
{
	username	= new_openid.username.value;
	qstr		= 'mode=username_exist&username=' + escape(username);  // NOTE: no '?' before querystring
	xmlhttpPost('query.php', qstr, check_username_result);
}

function check_email()
{	
	email = new_openid.email.value;
	
	if (is_valid_mail(email) == false)
	{
		document.getElementById("email_result").innerHTML = "{L_EMAIL_INVALID_EMAIL}";
		return;
	}

	qstr		= 'mode=email_exist&email=' + escape(email);  // NOTE: no '?' before querystring	
	xmlhttpPost('query.php', qstr, check_email_result);
}

function check_username_result()
{
	if (self.xmlHttpReq.readyState == 4)
	{
		
//		alert('check_username_result');
//		alert(self.xmlHttpReq.responseText);
		
		if (self.xmlHttpReq.responseText == '0')
		{
			str = "<img src=\"{T_THEME_PATH}/images/ok.jpg\" alt=\"icon\" />";
			document.getElementById("username_result").innerHTML = str;
			document.forms['new_openid'].username_check.value = 1;
			
//			alert('check_username_result ok');
		}
		else
		{
			document.getElementById("username_result").innerHTML = "{L_USERNAME_DISALLOWED_USERNAME}";
			document.forms['new_openid'].username_check.value = 0;
			
//			alert('check_username_result taken');
		}
	}
}

function check_email_result()
{
	if (self.xmlHttpReq.readyState == 4)
	{
//		alert('check_email_result');
//		alert(self.xmlHttpReq.responseText);
		
		if (self.xmlHttpReq.responseText == '0')
		{
			str = "<img src=\"{T_THEME_PATH}/images/ok.jpg\" alt=\"icon\" />";
			document.getElementById("email_result").innerHTML = str;
			document.forms['new_openid'].email_check.value = 1;
			
//			alert('check_email_result ok');
		}
		else
		{
			document.getElementById("email_result").innerHTML = "{L_EMAIL_TAKEN_EMAIL}";
			document.forms['new_openid'].email_check.value = 0;
			
//			alert('check_email_result taken');
		}
	}
}
</script>
<div class="panel">
	<div class="inner"><span class="corners-top"><span></span></span>
	
	<div class="content">
			<h2>{L_OPENID_VERIFY_OK}</h2>
			<p>{L_OPENID_VERIFIED}: {OPEN_ID}</p>
			
			<p>{L_OPENID_CREATE_EXPLAIN}</p>
			
        	<fieldset class="fields1">
        	<form name="new_openid" method="POST" action="openid_login.php?choice=create_new" onsubmit="return validate();">
        		
        		<input type="hidden" name="openid" value="{L_OPENID}" />
				<input type="hidden" name="register" value="register" />
				<table>
					<tr>
						<td><label for="username">{L_USERNAME}: </label></td>
						<td>
							<input type="text" name="username" class="inputbox autowidth" title="{L_USERNAME}" value="{OPENID_GUESS}" onchange="check_username();" />  							
						</td>
						<td>
							<div id="username_result"></div>
						</td>
					</tr>
					<tr>
						<td><label for="email" >{L_EMAIL}:</label></td>
						<td>
							<input type="text" name="email" class="inputbox autowidth" title="{L_EMAIL}" value="{EMAIL_FROM_SREG}" onchange="check_email();" />							
						</td>
						<td>
							<div id="email_result"></div>
						</td>
					</tr>
					<tr>
						<input type="hidden" name="username_check" value=0/>
						<input type="hidden" name="email_check" value=0/>
						<td colspan="2" style="text-align: right;"><input type="submit" name="login" value="{L_REGISTER}" class="button1" /></td>
					</tr>
				</table>
        	</form>
        	
        	</fieldset>
        
	</div>
	<span class="corners-bottom"><span></span></span></div>
</div>

<!-- INCLUDE overall_footer.html -->